﻿<Window x:Class="PluginTester.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:baka="clr-namespace:BakaBox.Controls;assembly=BakaBox"
        xmlns:manager="clr-namespace:Manga.Manager;assembly=Manga"
        Title="MainWindow" Height="350" Width="525" 
        DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" MinWidth="128"/>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <ListBox
            ItemsSource="{Binding Source={x:Static manager:Global_IMangaPluginCollection.Instance}, Path=Plugins}"
            SelectedItem="{Binding Path=SelectedPlugin, Mode=TwoWay}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=SiteName}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBox x:Name="URLBox" Text="{Binding Path=TestURL}" Margin="3,2">
                    <TextBox.InputBindings>
                        <KeyBinding 
                            Key="Enter" 
                            Command="{Binding TextBoxEnterKey}"
                            CommandParameter="{Binding ElementName=URLBox, Path=Text}"/>
                    </TextBox.InputBindings>
                </TextBox>
                <Button Content="Test" Grid.Column="1" Margin="2,1" Padding="10,0" Click="Button_Click" />
            </Grid>
            <TabControl Grid.Row="1" SelectedIndex="{Binding Path=SelectedTab}">
                <TabItem Header="Manga Info" DataContext="{Binding Path=MangInfo}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                                <TextBlock Text="{Binding Path=Site}"/>
                                <TextBlock Text="{Binding Path=Name}"/>
                                <TextBlock Text="{Binding Path=ID}"/>
                                <TextBlock>
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="v{0} c{1}.{2}">
                                            <Binding Path="Volume"/>
                                            <Binding Path="Chapter"/>
                                            <Binding Path="SubChapter"/>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                            </StackPanel>
                            <Border Grid.Column="1" Background="LightGray" BorderBrush="Black" BorderThickness="1">
                                <baka:StreamImage x:Name="Cover" AutoUpdate="True" MinWidth="36"/>
                            </Border>                            
                        </Grid>
                        <ListBox ItemsSource="{Binding Path=ChapterEntries}" Grid.Row="1" BorderThickness="0" MouseDoubleClick="ListBox_MouseDoubleClick">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock>
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="{}{0}: v{1} c{2}.{3}&#x0a;{4}">
                                                <Binding Path="Name"/>
                                                <Binding Path="Volume"/>
                                                <Binding Path="Chapter"/>
                                                <Binding Path="SubChapter"/>
                                                <Binding Path="UrlLink"/>
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </TabItem>
                <TabItem Header="Chapter Info" DataContext="{Binding Path=MangArch}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{Binding Path=Site}"/>
                            <TextBlock Text="{Binding Path=Name}"/>
                            <TextBlock Text="{Binding Path=ID}"/>
                            <TextBlock>
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="v{0} c{1}.{2}">
                                        <Binding Path="Volume"/>
                                        <Binding Path="Chapter"/>
                                        <Binding Path="SubChapter"/>
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                        </StackPanel>
                        <ListBox ItemsSource="{Binding Path=PageEntries}" Grid.Row="1" BorderThickness="0" MouseDoubleClick="ListBox_MouseDoubleClick">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock>
                                        <TextBlock.Text>                                            
                                            <MultiBinding StringFormat="{}{0}:&#x0a;{1}">
                                                <Binding Path="PageNumber"/>
                                                <Binding Path="LocationInfo.FullOnlinePath"/>
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </TabItem>
                <TabItem Header="Search">
                    <ListBox ItemsSource="{Binding Path=SearchResults}" MouseDoubleClick="ListBox_MouseDoubleClick">
                        <ListBox.Resources>
                            <Style TargetType="{x:Type ListBoxItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                            <Grid x:Name="ItemContainer" Cursor="Hand">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition/>
                                                    <RowDefinition/>
                                                </Grid.RowDefinitions>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="39"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <Border
                                                    BorderThickness="1"
                                                    BorderBrush="White"
                                                    HorizontalAlignment="Center"
                                                    VerticalAlignment="Center"
                                                    Margin="5"
                                                    Grid.RowSpan="2">
                                                    <Image 
                                                        MaxHeight="37"
                                                        MaxWidth="37"
                                                        Source="{Binding Path=CoverLocation}"/>
                                                </Border>
                                                <TextBlock 
                                                    Grid.Column="1"
                                                    Padding="5,0,0,0"
                                                    Text="{Binding Path=Title}"/>
                                                <TextBlock 
                                                    Grid.Column="1"
                                                    Grid.Row="1"
                                                    Padding="15,0,0,0"
                                                    Text="{Binding Path=Artist}"
                                                    FontSize="10"/>
                                            </Grid>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                                    <Setter TargetName="ItemContainer" Property="Background" Value="#DDD"/>
                                                </Trigger>
                                                <Trigger Property="IsSelected" Value="True">
                                                    <Setter TargetName="ItemContainer" Property="Background" Value="#AAA"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.Resources>
                    </ListBox>
                </TabItem>
            </TabControl>
        </Grid>
        
        <ProgressBar Grid.Row="1" Grid.ColumnSpan="2" Height="15" Value="{Binding Path=Progress}"/>
    </Grid>
</Window>
